/**
 * 通行证管理逻辑
 * Created by TomSean on 2017/5/31.
 */
var TrafficPermitManager = function ( $parent ) {
    this.$parent = $parent;
    this.sysUtils = new kendoUtils();
    this.init();
    return this;
}

TrafficPermitManager.prototype = {
    init : function () {
        var fieldArray = this.sysUtils.getBindFieldArray(this.$parent.find('.search-panel'));
        var functionArray = [
            { fName : 'find_data', fs : this.findData },
        ];
        this.models = new bindBaseModel(null, fieldArray, functionArray, null);
        this.sysUtils.bindDoucment(this.models, this.$parent, this);
        this.initTable();
        this.findData();
    },

    // 初始化列表
    initTable : function () {
        var $this = this;
        var columns = [
            {
                width : 30,
                headerTemplate : '<input type="checkbox" gridId="traffic_permit_data_list" onclick="gridCheckAll(this)">',
                template : '<input type="checkbox" name="traffic_permit_id" value="${uniqueIdentifier}">'
            },
            {
                title : '持卡人',
                field : 'pbaOwnerInfoByOwnerCode.ownerName'
            },
            {
                title : '印刷卡号',
                field : 'printingNo'
            },
            {
                title : '逻辑卡号',
                field : 'rationUniqueIdentifier'
            },
            {
                title : '物理卡号',
                field : 'physicNumber'
            },
            {
                title : '有效期',
                field : 'beginTime'
            },
            {
                title : '开卡时间',
                field : 'createTime'
            }
        ];
        this.sysUtils.createGird(this.$parent.find('#traffic_permit_data_list'),
            {
                selectable: 'single',
                autoSync: true,
                columnMenu: true,
                pageable: {input: true, numeric: false},
                columns: columns
            }
        );
    },

    // 查询
    findData : function (e) {
        var $this = this;
        if (!isEmpty(e)) {
            $this = $(e.target).data('that');
        }
        var dataT = {'jsonParam' : JSON.stringify($this.sysUtils.getBindDocJson($this.models.bindFieldArray))};
        var dataSource = $this.sysUtils.getDataSource({url : baseApiPath + 'traffic_permit/list', data : dataT, dataType : 'odata'});
        var grid = $this.$parent.find('#traffic_permit_data_list').data('kendoGrid');
        grid.setDataSource(dataSource);
    },
    openNewWindow : function (e) {
        var $this = this;
        if (!isEmpty(e)) {
            $this = $(e.target).data('that');
        }
        $this.openWindow('新开通行证');
    },

    openWindow : function ( title ) {
        this.editDiv = this.sysUtils.openWindow(this.editDiv, {
            title : title,
            width : 800,
            height: 550,
            content : 'views/parkLotCenter/parkingLotInfo/traffic_permit_edit.html'
        }, true);
    }
};